const fs = require('fs');
const archiver = require('archiver');
const path = require('path');

// Read package.json to get the version number
const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'), 'utf8'));
const version = packageJson.version;

// Create the output file stream with the version number in the filename
const output = fs.createWriteStream(`dist/senew-chrome-debug-v${version}.zip`);
const archive = archiver('zip', {
    zlib: { level: 9 } // Sets the compression level.
});

output.on('close', () => {
    console.log(archive.pointer() + ' total bytes');
    console.log('archiver has been finalized and the output file descriptor has closed.');
});

archive.on('warning', (err) => {
    if (err.code !== 'ENOENT') {
        throw err;
    }
});

archive.on('error', (err) => {
    throw err;
});

archive.pipe(output);

archive.directory('src/', false);

archive.finalize();